* the searched id is returned
* returns NULL if not found.
*/
-static struct cpupool *cpupool_find_by_id(int id, int exact)
+static struct cpupool *__cpupool_find_by_id(int id, int exact)
{
struct cpupool **q;
if ( (*q)->cpupool_id >= id )
break;
- return (!exact || ((*q)->cpupool_id == id)) ? *q : NULL;
+ return (!exact || (*q == NULL) || ((*q)->cpupool_id == id)) ? *q : NULL;
+}
+
+static struct cpupool *cpupool_find_by_id(int poolid)
+{
+ return __cpupool_find_by_id(poolid, 1);
}
static struct cpupool *__cpupool_get_by_id(int poolid, int exact)
{
struct cpupool *c;
spin_lock(&cpupool_lock);
- c = cpupool_find_by_id(poolid, exact);
+ c = __cpupool_find_by_id(poolid, exact);
if ( c != NULL )
atomic_inc(&c->refcnt);
spin_unlock(&cpupool_lock);
return __cpupool_get_by_id(poolid, 1);
}
+static struct cpupool *cpupool_get_next_by_id(int poolid)
+{
+ return __cpupool_get_by_id(poolid, 0);
+}
+
void cpupool_put(struct cpupool *pool)
{
if ( !atomic_dec_and_test(&pool->refcnt) )
if ( poolid == CPUPOOLID_NONE )
return 0;
spin_lock(&cpupool_lock);
- c = cpupool_find_by_id(poolid, 1);
+ c = cpupool_find_by_id(poolid);
if ( (c != NULL) && cpus_weight(c->cpu_valid) )
{
c->n_dom++;
case XEN_SYSCTL_CPUPOOL_OP_INFO:
{
- c = __cpupool_get_by_id(op->cpupool_id, 0);
+ c = cpupool_get_next_by_id(op->cpupool_id);
ret = -ENOENT;
if ( c == NULL )
break;
ret = -EBUSY;
if ( !cpu_isset(cpu, cpupool_free_cpus) )
goto addcpu_out;
- c = cpupool_find_by_id(op->cpupool_id, 1);
+ c = cpupool_find_by_id(op->cpupool_id);
ret = -ENOENT;
if ( c == NULL )
goto addcpu_out;
{
unsigned cpu;
- c = __cpupool_get_by_id(op->cpupool_id, 1);
+ c = cpupool_get_by_id(op->cpupool_id);
ret = -ENOENT;
if ( c == NULL )
break;
d->domain_id, op->cpupool_id);
ret = -ENOENT;
spin_lock(&cpupool_lock);
- c = cpupool_find_by_id(op->cpupool_id, 1);
+ c = cpupool_find_by_id(op->cpupool_id);
if ( (c != NULL) && cpus_weight(c->cpu_valid) )
{
d->cpupool->n_dom--;